// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.CrossClusterReplication;

public sealed partial class FollowRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)</para>
	/// </summary>
	public Elastic.Clients.Elasticsearch.WaitForActiveShards? WaitForActiveShards { get => Q<Elastic.Clients.Elasticsearch.WaitForActiveShards?>("wait_for_active_shards"); set => Q("wait_for_active_shards", value); }
}

/// <summary>
/// <para>Creates a new follower index configured to follow the referenced leader index.</para>
/// </summary>
public sealed partial class FollowRequest : PlainRequest<FollowRequestParameters>
{
	public FollowRequest(Elastic.Clients.Elasticsearch.IndexName index) : base(r => r.Required("index", index))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.CrossClusterReplicationFollow;

	protected override HttpMethod StaticHttpMethod => HttpMethod.PUT;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ccr.follow";

	/// <summary>
	/// <para>Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)</para>
	/// </summary>
	[JsonIgnore]
	public Elastic.Clients.Elasticsearch.WaitForActiveShards? WaitForActiveShards { get => Q<Elastic.Clients.Elasticsearch.WaitForActiveShards?>("wait_for_active_shards"); set => Q("wait_for_active_shards", value); }
	[JsonInclude, JsonPropertyName("leader_index")]
	public Elastic.Clients.Elasticsearch.IndexName? LeaderIndex { get; set; }
	[JsonInclude, JsonPropertyName("max_outstanding_read_requests")]
	public long? MaxOutstandingReadRequests { get; set; }
	[JsonInclude, JsonPropertyName("max_outstanding_write_requests")]
	public long? MaxOutstandingWriteRequests { get; set; }
	[JsonInclude, JsonPropertyName("max_read_request_operation_count")]
	public long? MaxReadRequestOperationCount { get; set; }
	[JsonInclude, JsonPropertyName("max_read_request_size")]
	public string? MaxReadRequestSize { get; set; }
	[JsonInclude, JsonPropertyName("max_retry_delay")]
	public Elastic.Clients.Elasticsearch.Duration? MaxRetryDelay { get; set; }
	[JsonInclude, JsonPropertyName("max_write_buffer_count")]
	public long? MaxWriteBufferCount { get; set; }
	[JsonInclude, JsonPropertyName("max_write_buffer_size")]
	public string? MaxWriteBufferSize { get; set; }
	[JsonInclude, JsonPropertyName("max_write_request_operation_count")]
	public long? MaxWriteRequestOperationCount { get; set; }
	[JsonInclude, JsonPropertyName("max_write_request_size")]
	public string? MaxWriteRequestSize { get; set; }
	[JsonInclude, JsonPropertyName("read_poll_timeout")]
	public Elastic.Clients.Elasticsearch.Duration? ReadPollTimeout { get; set; }
	[JsonInclude, JsonPropertyName("remote_cluster")]
	public string? RemoteCluster { get; set; }
}

/// <summary>
/// <para>Creates a new follower index configured to follow the referenced leader index.</para>
/// </summary>
public sealed partial class FollowRequestDescriptor<TDocument> : RequestDescriptor<FollowRequestDescriptor<TDocument>, FollowRequestParameters>
{
	internal FollowRequestDescriptor(Action<FollowRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public FollowRequestDescriptor(Elastic.Clients.Elasticsearch.IndexName index) : base(r => r.Required("index", index))
	{
	}

	public FollowRequestDescriptor() : this(typeof(TDocument))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.CrossClusterReplicationFollow;

	protected override HttpMethod StaticHttpMethod => HttpMethod.PUT;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ccr.follow";

	public FollowRequestDescriptor<TDocument> WaitForActiveShards(Elastic.Clients.Elasticsearch.WaitForActiveShards? waitForActiveShards) => Qs("wait_for_active_shards", waitForActiveShards);

	public FollowRequestDescriptor<TDocument> Index(Elastic.Clients.Elasticsearch.IndexName index)
	{
		RouteValues.Required("index", index);
		return Self;
	}

	private Elastic.Clients.Elasticsearch.IndexName? LeaderIndexValue { get; set; }
	private long? MaxOutstandingReadRequestsValue { get; set; }
	private long? MaxOutstandingWriteRequestsValue { get; set; }
	private long? MaxReadRequestOperationCountValue { get; set; }
	private string? MaxReadRequestSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? MaxRetryDelayValue { get; set; }
	private long? MaxWriteBufferCountValue { get; set; }
	private string? MaxWriteBufferSizeValue { get; set; }
	private long? MaxWriteRequestOperationCountValue { get; set; }
	private string? MaxWriteRequestSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? ReadPollTimeoutValue { get; set; }
	private string? RemoteClusterValue { get; set; }

	public FollowRequestDescriptor<TDocument> LeaderIndex(Elastic.Clients.Elasticsearch.IndexName? leaderIndex)
	{
		LeaderIndexValue = leaderIndex;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxOutstandingReadRequests(long? maxOutstandingReadRequests)
	{
		MaxOutstandingReadRequestsValue = maxOutstandingReadRequests;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxOutstandingWriteRequests(long? maxOutstandingWriteRequests)
	{
		MaxOutstandingWriteRequestsValue = maxOutstandingWriteRequests;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxReadRequestOperationCount(long? maxReadRequestOperationCount)
	{
		MaxReadRequestOperationCountValue = maxReadRequestOperationCount;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxReadRequestSize(string? maxReadRequestSize)
	{
		MaxReadRequestSizeValue = maxReadRequestSize;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxRetryDelay(Elastic.Clients.Elasticsearch.Duration? maxRetryDelay)
	{
		MaxRetryDelayValue = maxRetryDelay;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxWriteBufferCount(long? maxWriteBufferCount)
	{
		MaxWriteBufferCountValue = maxWriteBufferCount;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxWriteBufferSize(string? maxWriteBufferSize)
	{
		MaxWriteBufferSizeValue = maxWriteBufferSize;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxWriteRequestOperationCount(long? maxWriteRequestOperationCount)
	{
		MaxWriteRequestOperationCountValue = maxWriteRequestOperationCount;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> MaxWriteRequestSize(string? maxWriteRequestSize)
	{
		MaxWriteRequestSizeValue = maxWriteRequestSize;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> ReadPollTimeout(Elastic.Clients.Elasticsearch.Duration? readPollTimeout)
	{
		ReadPollTimeoutValue = readPollTimeout;
		return Self;
	}

	public FollowRequestDescriptor<TDocument> RemoteCluster(string? remoteCluster)
	{
		RemoteClusterValue = remoteCluster;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (LeaderIndexValue is not null)
		{
			writer.WritePropertyName("leader_index");
			JsonSerializer.Serialize(writer, LeaderIndexValue, options);
		}

		if (MaxOutstandingReadRequestsValue.HasValue)
		{
			writer.WritePropertyName("max_outstanding_read_requests");
			writer.WriteNumberValue(MaxOutstandingReadRequestsValue.Value);
		}

		if (MaxOutstandingWriteRequestsValue.HasValue)
		{
			writer.WritePropertyName("max_outstanding_write_requests");
			writer.WriteNumberValue(MaxOutstandingWriteRequestsValue.Value);
		}

		if (MaxReadRequestOperationCountValue.HasValue)
		{
			writer.WritePropertyName("max_read_request_operation_count");
			writer.WriteNumberValue(MaxReadRequestOperationCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxReadRequestSizeValue))
		{
			writer.WritePropertyName("max_read_request_size");
			writer.WriteStringValue(MaxReadRequestSizeValue);
		}

		if (MaxRetryDelayValue is not null)
		{
			writer.WritePropertyName("max_retry_delay");
			JsonSerializer.Serialize(writer, MaxRetryDelayValue, options);
		}

		if (MaxWriteBufferCountValue.HasValue)
		{
			writer.WritePropertyName("max_write_buffer_count");
			writer.WriteNumberValue(MaxWriteBufferCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxWriteBufferSizeValue))
		{
			writer.WritePropertyName("max_write_buffer_size");
			writer.WriteStringValue(MaxWriteBufferSizeValue);
		}

		if (MaxWriteRequestOperationCountValue.HasValue)
		{
			writer.WritePropertyName("max_write_request_operation_count");
			writer.WriteNumberValue(MaxWriteRequestOperationCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxWriteRequestSizeValue))
		{
			writer.WritePropertyName("max_write_request_size");
			writer.WriteStringValue(MaxWriteRequestSizeValue);
		}

		if (ReadPollTimeoutValue is not null)
		{
			writer.WritePropertyName("read_poll_timeout");
			JsonSerializer.Serialize(writer, ReadPollTimeoutValue, options);
		}

		if (!string.IsNullOrEmpty(RemoteClusterValue))
		{
			writer.WritePropertyName("remote_cluster");
			writer.WriteStringValue(RemoteClusterValue);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>Creates a new follower index configured to follow the referenced leader index.</para>
/// </summary>
public sealed partial class FollowRequestDescriptor : RequestDescriptor<FollowRequestDescriptor, FollowRequestParameters>
{
	internal FollowRequestDescriptor(Action<FollowRequestDescriptor> configure) => configure.Invoke(this);

	public FollowRequestDescriptor(Elastic.Clients.Elasticsearch.IndexName index) : base(r => r.Required("index", index))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.CrossClusterReplicationFollow;

	protected override HttpMethod StaticHttpMethod => HttpMethod.PUT;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ccr.follow";

	public FollowRequestDescriptor WaitForActiveShards(Elastic.Clients.Elasticsearch.WaitForActiveShards? waitForActiveShards) => Qs("wait_for_active_shards", waitForActiveShards);

	public FollowRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName index)
	{
		RouteValues.Required("index", index);
		return Self;
	}

	private Elastic.Clients.Elasticsearch.IndexName? LeaderIndexValue { get; set; }
	private long? MaxOutstandingReadRequestsValue { get; set; }
	private long? MaxOutstandingWriteRequestsValue { get; set; }
	private long? MaxReadRequestOperationCountValue { get; set; }
	private string? MaxReadRequestSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? MaxRetryDelayValue { get; set; }
	private long? MaxWriteBufferCountValue { get; set; }
	private string? MaxWriteBufferSizeValue { get; set; }
	private long? MaxWriteRequestOperationCountValue { get; set; }
	private string? MaxWriteRequestSizeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? ReadPollTimeoutValue { get; set; }
	private string? RemoteClusterValue { get; set; }

	public FollowRequestDescriptor LeaderIndex(Elastic.Clients.Elasticsearch.IndexName? leaderIndex)
	{
		LeaderIndexValue = leaderIndex;
		return Self;
	}

	public FollowRequestDescriptor MaxOutstandingReadRequests(long? maxOutstandingReadRequests)
	{
		MaxOutstandingReadRequestsValue = maxOutstandingReadRequests;
		return Self;
	}

	public FollowRequestDescriptor MaxOutstandingWriteRequests(long? maxOutstandingWriteRequests)
	{
		MaxOutstandingWriteRequestsValue = maxOutstandingWriteRequests;
		return Self;
	}

	public FollowRequestDescriptor MaxReadRequestOperationCount(long? maxReadRequestOperationCount)
	{
		MaxReadRequestOperationCountValue = maxReadRequestOperationCount;
		return Self;
	}

	public FollowRequestDescriptor MaxReadRequestSize(string? maxReadRequestSize)
	{
		MaxReadRequestSizeValue = maxReadRequestSize;
		return Self;
	}

	public FollowRequestDescriptor MaxRetryDelay(Elastic.Clients.Elasticsearch.Duration? maxRetryDelay)
	{
		MaxRetryDelayValue = maxRetryDelay;
		return Self;
	}

	public FollowRequestDescriptor MaxWriteBufferCount(long? maxWriteBufferCount)
	{
		MaxWriteBufferCountValue = maxWriteBufferCount;
		return Self;
	}

	public FollowRequestDescriptor MaxWriteBufferSize(string? maxWriteBufferSize)
	{
		MaxWriteBufferSizeValue = maxWriteBufferSize;
		return Self;
	}

	public FollowRequestDescriptor MaxWriteRequestOperationCount(long? maxWriteRequestOperationCount)
	{
		MaxWriteRequestOperationCountValue = maxWriteRequestOperationCount;
		return Self;
	}

	public FollowRequestDescriptor MaxWriteRequestSize(string? maxWriteRequestSize)
	{
		MaxWriteRequestSizeValue = maxWriteRequestSize;
		return Self;
	}

	public FollowRequestDescriptor ReadPollTimeout(Elastic.Clients.Elasticsearch.Duration? readPollTimeout)
	{
		ReadPollTimeoutValue = readPollTimeout;
		return Self;
	}

	public FollowRequestDescriptor RemoteCluster(string? remoteCluster)
	{
		RemoteClusterValue = remoteCluster;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (LeaderIndexValue is not null)
		{
			writer.WritePropertyName("leader_index");
			JsonSerializer.Serialize(writer, LeaderIndexValue, options);
		}

		if (MaxOutstandingReadRequestsValue.HasValue)
		{
			writer.WritePropertyName("max_outstanding_read_requests");
			writer.WriteNumberValue(MaxOutstandingReadRequestsValue.Value);
		}

		if (MaxOutstandingWriteRequestsValue.HasValue)
		{
			writer.WritePropertyName("max_outstanding_write_requests");
			writer.WriteNumberValue(MaxOutstandingWriteRequestsValue.Value);
		}

		if (MaxReadRequestOperationCountValue.HasValue)
		{
			writer.WritePropertyName("max_read_request_operation_count");
			writer.WriteNumberValue(MaxReadRequestOperationCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxReadRequestSizeValue))
		{
			writer.WritePropertyName("max_read_request_size");
			writer.WriteStringValue(MaxReadRequestSizeValue);
		}

		if (MaxRetryDelayValue is not null)
		{
			writer.WritePropertyName("max_retry_delay");
			JsonSerializer.Serialize(writer, MaxRetryDelayValue, options);
		}

		if (MaxWriteBufferCountValue.HasValue)
		{
			writer.WritePropertyName("max_write_buffer_count");
			writer.WriteNumberValue(MaxWriteBufferCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxWriteBufferSizeValue))
		{
			writer.WritePropertyName("max_write_buffer_size");
			writer.WriteStringValue(MaxWriteBufferSizeValue);
		}

		if (MaxWriteRequestOperationCountValue.HasValue)
		{
			writer.WritePropertyName("max_write_request_operation_count");
			writer.WriteNumberValue(MaxWriteRequestOperationCountValue.Value);
		}

		if (!string.IsNullOrEmpty(MaxWriteRequestSizeValue))
		{
			writer.WritePropertyName("max_write_request_size");
			writer.WriteStringValue(MaxWriteRequestSizeValue);
		}

		if (ReadPollTimeoutValue is not null)
		{
			writer.WritePropertyName("read_poll_timeout");
			JsonSerializer.Serialize(writer, ReadPollTimeoutValue, options);
		}

		if (!string.IsNullOrEmpty(RemoteClusterValue))
		{
			writer.WritePropertyName("remote_cluster");
			writer.WriteStringValue(RemoteClusterValue);
		}

		writer.WriteEndObject();
	}
}